package com.lcc.forum.demos.web.controller;

import com.lcc.forum.demos.web.common.AppResult;
import com.lcc.forum.demos.web.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

//表示返回的结果是数据
@RestController
//定义一级映射路径
@RequestMapping("/test")
@Api(tags = "测试类的相关接口")
public class TestController {
    @ApiOperation("测试接口1,显示hello,Spring Boot")
    @GetMapping("/hello")
    public String hello(){
        return "hello,Spring Boot...";
    }
    //测试异常
    @ApiOperation("测试接口2,显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception......");
    }
    @ApiOperation("测试接口3,显示自定义的异常信息")
    @GetMapping("/appException")
    public AppResult testApplicationExcetion(){
        throw new ApplicationException("这是一个ApplicationExcetion......");
    }
    @PostMapping("/testName")
    public String testName(@ApiParam("显示名字") @RequestParam("name") String name){
        return "Name:"+name;
    }

}
